//
//  ZQNavigationController.swift
//  ZQWeibo
//
//  Created by summer的Dad on 16/11/12.
//  Copyright © 2016年 summer的Dad. All rights reserved.
//

import UIKit

class ZQNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

     
        
        
        
    }
    
//    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
//        
//        let count = childViewControllers.count
//        
//        if count > 0 {
//            
//            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
//            
//            
//            viewController.hidesBottomBarWhenPushed = true
//            
//        }
//        
//        self.pushViewController(viewController, animated: animated)
//        
//        
//    }
//    
//    @objc private func back () {
//        
//        popViewController(animated: true)
//        
//    }
    
    
    
    //说明UINavigationController(rootViewController:) 内部执行了push的操作
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        let count = childViewControllers.count
        if count > 0 {
            //统一操作
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"返回",imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
            //隐藏底部的tabbar
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back() {
        popViewController(animated: true)
    }
    

    


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
